package com.liang.service.impl;



import com.liang.mapper.UserzDAO;
import com.liang.pojo.Userz;
import com.liang.service.UserzService;
import com.liang.utils.DateUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 *@作者:lsk
 *Service实现类
 *@Date:2023/10/11
*/
@Service
public class UserzServiceImpl implements UserzService {


	@Resource
	private UserzDAO userzdao;


	/**
	 * 查询用户所属军队,和职务和信息
	 */
	@Override
	public Object selectUserInforArmy(Map param) {
		if(param.get("pageNum") != null){
			int start = Integer.parseInt(param.get("pageSize").toString()) * (Integer.parseInt(param.get("pageNum").toString()) - 1);
			param.put("pageNum",start);
		}
		return userzdao.selectUserInforArmy(param);
	}

	/**
	根据User_id查询
	*/
	public Object selectByUser_id(Long user_id){
		return userzdao.selectByUser_id(user_id);
	}


	/**
	根据User_id更新
	*/
	public Integer updateByUser_id(Userz demo){

		if(demo.getUser_id() == null){
			return 0;
		}
		demo.setUpdate_time(DateUtils.getTodayDateTime());
		return userzdao.updateByUser_id( demo);

	}



	/**
	根据User_id删除
	*/
	public Integer deleteByUser_id(Long user_id){
		return userzdao.deleteByUser_id(user_id);
	}





	/**
	 insert:(插入)
	*/
	public Object insert(Userz demo){
		demo.setCreat_time(DateUtils.getTodayDateTime());
		demo.setUser_password("wmGsEEZJ3XyqbpjrBpYcHQ==");
		userzdao.insertlsk(demo);
		return demo;
	}



	/**
	 insertOrUpdate(插入或更新(根据主键或唯一索引更新，主键和唯一索引不会改变))
	*/
	public Integer insertOrUpdate(Userz demo){
		if(demo.getUser_password() != null && !demo.getUser_password().equals("")){
			demo.setUser_password("wmGsEEZJ3XyqbpjrBpYcHQ==");
		}
		return userzdao.insertOrUpdatelsk(demo);
	}



	/**
	 insertBath:(批量插入)
	*/
	public Integer insertBatch(List<Userz> list){
		return userzdao.insertBatchlsk(list);
	}



	/**
	 insertOrUpdateBatch:(批量插入或更新)
	*/
	public Integer insertOrUpdateBatch(List<Userz> list){
		return userzdao.insertOrUpdateBatchlsk(list);
	}



	/**
	 selectList:(根据参数查询集合)
	*/
	public List<Userz> selectList(Map<String,Object> param){
		if(param.get("pageNum") != null){
			int start = Integer.parseInt(param.get("pageSize").toString()) * (Integer.parseInt(param.get("pageNum").toString()) - 1);
			param.put("pageNum",start);
		}
		return userzdao.selectListlsk(param);
	}



	/**
	 selectCount:(根据集合查询数量)
	*/
	public Long selectCount(Map<String,Object> param){
		return userzdao.selectCountlsk(param);
	}



}